import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  BaseEntity,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
} from 'typeorm';

@Entity()
export class User extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true })
  email: string;

  @Column({ nullable: true })
  name: string;

  @Column({ unique: true })
  username: string;

  @Column({ comment: '密码' })
  password: string;

  @Column({
    nullable: true,
    default: 'https://ext1688.oss-us-west-1.aliyuncs.com/loading/avatar.jpg',
  })
  avatar: string;

  @Column({ nullable: true })
  phone: string;

  @Column({ default: true })
  isShow: boolean;

  @Column({ comment: '邮箱是否确认', nullable: true, default: false })
  emailEnter: boolean;

  /**
   * 用户等级
   */
  @Column({ nullable: true, default: 1 })
  level: number;
  /**
   * 费率
   */
  @Column({ nullable: true, default: 10 })
  rate: number;

  /**
   * 邀请码
   */
  @Column({ nullable: true, unique: true })
  inviteCode: string;

  /**
   * 邀请人
   */
  @Column({ nullable: true })
  inviteId: number;

  @Column({ nullable: true, default: 0 })
  bonusRatio: number;

  /**
   * 分红余额 只计算分红
   */
  @Column({ default: 0, type: 'decimal', precision: 10, scale: 2 })
  bonusBalance: number;

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;

  @DeleteDateColumn({ nullable: true })
  deleteTime: Date;
}
